<?php
$section = 1;
include("includes/secure.php");
include("../includes/config.php");
include("../includes/class/user.class.php");
require_once("../includes/class/fileManagement.class.php");

$user = new User(); 
$file = new fileManagement();

$edit_code	= $_GET['code'];

if(isset($_POST['editar']) && $_POST['editar'] == 1)
{
	$new_data->edit_code	= $edit_code;
	$new_data->name 		= mysql_real_escape_string($_POST['name']);
	$new_data->dependencia 	= mysql_real_escape_string($_POST['dependencia']);
	$new_data->email    	= mysql_real_escape_string($_POST['email']);
	$new_data->phone	    = mysql_real_escape_string($_POST['phone']);
	$new_data->login 		= mysql_real_escape_string($_POST['login']);
	$new_data->password 	= md5(mysql_real_escape_string($_POST['password']));		
	$new_data->status 		= mysql_real_escape_string($_POST['status']);	
	$new_data->type 		= mysql_real_escape_string($_POST['type']);		
	
	if($_POST['login'] != $_POST['login_ant'] || $_POST['password'] != '')
			$new_data->password 	= md5($new_data->login.mysql_real_escape_string($_POST['password']).$new_data->login);
		else
			$new_data->password 	= mysql_real_escape_string($_POST['passAnt']);	
				
	if(isset($_FILES['archivo']))
	{
		for($i=0;$i<sizeof($_FILES['archivo']['tmp_name']);$i++)
		{
			if(is_uploaded_file($_FILES['archivo']['tmp_name'][$i]))
			{
				$document = $file->subirArchivo($_FILES['archivo']['tmp_name'][$i],$_FILES['archivo']['name'][$i],'file_upload/documentos/');					 
				$new_data->original 	= $_FILES['archivo']['name'][$i];
				$new_data->renam     	= $document;						
			} 		
		}
	}
	
	if($user->editUser($new_data))
	{	
		echo "<script>alert('Registro actualizado exitosamente')</script>";	
		echo "<script>window.location.href='list_user.php'</script>";			
	}
	else
	{		
		echo "<script>alert('El registro no se modifico')</script>";	
		echo "<script>window.location.href='list_user.php'</script>";	
	}	
}
else
	{
		$datos_editar = $user->getUserData($edit_code);	
		
		$user_types[0] = 'Administrador';
		$user_types[1] = 'Dependencia';
				
	}
	

?>
